<?php
session_start();
header('Content-Type: text/html; charset=utf-8');

///
include_once( 'config2.php' );
include_once( 'weibooauth.php' );

///
$o = new WeiboOAuth( WB_AKEY , WB_SKEY  );
$keys = $o->getRequestToken();
$_SESSION['keys'] = $keys;


///
$uri = substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/'));
$phpSelf = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/'));
if (empty($phpSelf) || strpos($uri, $phpSelf) === false) 
	$phpSelf = '';
	
$domain = 'http://'.$_SERVER['SERVER_NAME'].htmlspecialchars(preg_replace("/\/+(api|archiver|wap)?\/*$/i", '', $phpSelf) . '/');
$aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , $domain.'callback.php' );
?>

<a href="<?=$aurl?>">点击登录</a>
